<%@ page pageEncoding="UTF-8" contentType="text/html; charset=utf-8"  %>
<%
	System.out.println("starting save");		
	org.languageguide.user.User user = org.languageguide.user.UserManager.getUser(session);
	if (user == null){
		System.out.println("user not logged in");		
		return;
	}
	String id = request.getParameter("id");
	String targetLanguage = request.getParameter("target");
	String text = request.getParameter("text");
	String status = request.getParameter("status");	
	String checkinStr = request.getParameter("checkin");	
	boolean checkin = Boolean.getBoolean(checkinStr);
	System.out.println("id" + id + " " + text);
	org.languageguide.readings.TranslatedReading reading = org.languageguide.readings.ReadingManager.getReading(id, targetLanguage);
	
	if (reading != null){
		//if (reading.checkedOut(user)){
			//System.out.println("check in");
			boolean success = reading.save(user, text, status, checkin);
			if (success){
				System.out.println("saved");
				response.setContentType("text/xml");
				response.setHeader("Cache-Control", "no-cache");
				response.getWriter().write("<message>valid: yo Buddy</message>"); 
			}
			else{
					System.out.println("not saved");
				response.setContentType("text/xml");
				response.setHeader("Cache-Control", "no-cache");
				response.getWriter().write("<message>invalid: yo Buddy</message>"); 
			}
		//}
		//else {
			//System.out.println("Error: save failed");
		//}
	}
	else{
		System.out.println("Error: reading not found");
	}
	

%>